class Prime{
	public static void printPrime(int n){
		int i,j,sqr;
		boolean isPrime;
		for (i=1;i<=n;i++){
			isPrime = true;
			 sqr = (int)Math.sqrt(i); // or sqr = i/2;
			for (j=2;j<=sqr;j++){ //prime are all odd
				if(i%j == 0){
					isPrime = false;
					break;
				}
			}
			if(isPrime){
				System.out.print(" "+i);
			}
		}
	}
	
	public static void main(String[] args){
		printPrime(40);
	}
}